// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'

//npm install vue-resource --save-dev
import VueResource from 'vue-resource'
Vue.use(VueResource)
//引入element组件开发npm i element-ui -S
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI,{ size: 'small' })
//引入网页title插件使用npm install vue-wechat-title --save
import VueWechatTitle from 'vue-wechat-title';  
Vue.use(VueWechatTitle)

//vue的全局变量
import Global_ from '../static/js/config/Global'
Vue.prototype.GLOBAL = Global_;


//拦截器设置全局请求token
Vue.http.interceptors.push((request, next) => {
		if(localStorage.getItem('userInfo')!="null"&&localStorage.getItem('userInfo')!=""&&localStorage.getItem('userInfo')!=null){
			request.headers.set('Authorization',JSON.parse(localStorage.getItem('userInfo')).token); //设置请求头
			request.headers.set('Content-Type','application/json;charset=UTF-8'); //设置请求头
		}
		// request.headers.set('us','web'); //设置web后台标识
		//设置请求时间
		let timeout;
		// 如果某个请求设置了_timeout,那么超过该时间，会终端该（abort）请求,并执行请求设置的钩子函数onTimeout方法，不会执行then方法。
		if (request._timeout) {
			timeout = setTimeout(() => {
				if(request.onTimeout) {
					request.onTimeout(request);
					request.abort()
				}  
			}, request._timeout);
		}
		next((response) => {
			clearTimeout(timeout);
			console.log(response.status)
			return response
		})
})


Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
